//
//  PaperCardCollectionViewCell.m
//  ZYOnlineSchool
//
//  Created by 毕武侠 on 2017/3/15.
//  Copyright © 2017年 bwx. All rights reserved.
//

#import "PaperCardCollectionViewCell.h"
#import "PaperAnalyModel.h"

@interface PaperCardCollectionViewCell ()

@property (weak, nonatomic) IBOutlet UIView *backView;
@property (weak, nonatomic) IBOutlet UILabel *num;

@end

@implementation PaperCardCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.backView.layer.borderColor = RGB(180, 180, 180).CGColor;
    self.backView.layer.borderWidth = 0.8f;
    self.backView.layer.cornerRadius = 42.0f/2;//(SCREEN_WIDTH - 160.0f) / 10;
    self.backView.layer.masksToBounds = YES;
}

- (void)bindModel:(PaperBaseModel *)model {
    if ([model isKindOfClass:[PaperAnalyModel class]]) {
        PaperAnalyModel *analyModel = (PaperAnalyModel *)model;
        if (analyModel.right_answer == nil && analyModel.user_selected == nil) {
            if (model.ques_model == 0 ) {        // 单选
                if (model.index != NSNotFound) {
                    [self showRightView];
                } else {
                    [self showNormalView];
                }
            } else if(model.ques_model == 1){  // 多选
                if (model.index > 0) {
                    [self showRightView];
                } else {
                    [self showNormalView];
                }
            }
        } else {
            if ([analyModel.right_answer isEqualToString:analyModel.user_selected]) {
                [self showRightView];
            } else if ([analyModel.user_selected isEqualToString:@"未作答"]){
                [self showNormalView];
            } else {
                [self showWrongView];
            }
        }
    } else if ([model isKindOfClass:[PaperAnswerModel class]]) {
        if (model.ques_model == 0 ) {    // 单选
            if (model.index != NSNotFound) {
                [self showRightView];
            } else {
                [self showNormalView];
            }
        } else if(model.ques_model == 1){ //多选                           // 多选
            if (model.index > 0) {
                [self showRightView];
            } else {
                [self showNormalView];
            }
        }else if (model.ques_model == 2){//问答
            if (model.user_content && model.user_content.length > 0) {
                [self showRightView];
            }else{
                [self showNormalView];
                
            }
        }
        
    } else {
        
            [self showNormalView];
    }
    self.num.text = [NSString stringWithFormat:@"%ld", model.ques_num];
}

- (void)showNormalView {
    self.backView.layer.borderWidth = 0.8f;
    self.backView.layer.borderColor = RGB(180, 180, 180).CGColor;
    self.backView.backgroundColor = [UIColor whiteColor];
    self.num.textColor = MainThemeColor;
}

- (void)showWrongView {
    self.backView.layer.borderWidth = 0.0f;
    self.backView.layer.borderColor = RGB(255, 35, 68).CGColor;
    self.backView.backgroundColor = RGB(255, 35, 68);
    self.num.textColor = [UIColor whiteColor];
}

- (void)showRightView {
    self.backView.layer.borderWidth = 0.0f;
    self.backView.layer.borderColor = MainThemeColor.CGColor;
    self.backView.backgroundColor = MainThemeColor;
    self.num.textColor = [UIColor whiteColor];
}

@end
